#include "monster.h"

//constructors

Monster::Monster()
{
    name = "unknown";
    health = level = health_max = PowAttack = PowDef = MagAttack = MagDef = exper = gold_nuggets = mana = mana_max = 1;
}

void Monster::setAll(string nm, int hlth, int hlth_max, int mna, int mna_max, int lv,
                     int PAttk, int PDef, int MAttk, int MDef, int exp, int gold)
{
    name = nm;
    health = hlth;
    health_max = hlth_max;
    level = lv;
    PowAttack = PAttk;
    PowDef = PDef;
    MagAttack = MAttk;
    MagDef = MDef;
    exper = exp;
    gold_nuggets = gold;
    mana = mna;
    mana_max = mna_max;
}

Monster::Monster(const Monster &other)
{
    name = other.name;
    health = other.health;
    health_max = other.health_max;
    level = other.level;
    PowAttack = other.PowAttack;
    PowDef = other.PowDef;
    MagAttack = other.MagAttack;
    MagDef = other.MagDef;
    exper = other.exper;
    gold_nuggets = other.gold_nuggets;
}

//mutators

void Monster::setExp(int exp)
{ exper = exp; }

void Monster::setGold(int gold)
{ gold_nuggets = gold; }

void Monster::setLevel(int lv)
{ level = lv; }

void Monster::setMAttk(int MAttk)
{ MagAttack = MAttk; }

void Monster::setMDef(int MDef)
{ MagDef = MDef; }

void Monster::setName(string nm)
{ name = nm; }

void Monster::setPAttk(int PAttk)
{ PowAttack = PAttk; }

void Monster::setPDef(int PDef)
{ PowDef = PDef; }

void Monster::setHealth(int hlth)
{ health = hlth; }

void Monster::setHealthMax(int hlth_max)
{ health_max = hlth_max; }

void Monster::HealthToMax()
{ health = health_max; }

void Monster::ManaToMax()
{ mana = mana_max; }

void Monster::setMana(int mna)
{ mana = mna; }

void Monster::setManaMax(int mna_max)
{ mana_max = mna_max; }

//action functions / accessors

bool Monster::isDead()
{ return (health <= 0); }

int Monster::attack()
{
    int answer = rand() % PowAttack + 1;
    return answer;
}

int Monster::defend()
{
    int answer = rand() % PowDef + 1;
    return answer;
}

int Monster::getExp()
{ return exper; }

int Monster::getGold()
{ return gold_nuggets; }

int Monster::Mattack()
{
    if(mana == 0)
    {
        cout << "---Out of Mana---\n";
        return 0;
    }
    int answer = rand() % MagAttack + 1;
    if(mana - answer <= 0)
        mana = 0;
    return answer;
}

int Monster::Mdefend()
{
    int answer = rand() % MagDef + 1;
    return answer;
}

string Monster::getName()
{
    return name;
}

int Monster::getHealth()
{
    return health;
}

int Monster::getLvl()
{
    return level;
}

int Monster::getMana()
{
    return mana;
}

int Monster::battleAction(int code)
{
    int action = rand() % 3;
    if (code == 1)
    {
        if (action == 0)
        {
            cout << "Attack---\n";
            return attack();
        }
        if (action == 1) //remove?
        {
            cout << "Miss---\n";
            return 0;
        }
        else
        {
            cout << "Magic Attack---\n";
            return Mattack();
        }
    }
    if (code == 2)
    {
        if (action == 0)
        {
            cout << "Defense---\n";
            return defend();
        }
        if (action == 1) //remove?
        {
            cout << "Caught off Guard!---\n";
            return 0;
        }
        else
        {
            cout << "Magic Defense---\n";
            return Mdefend();
        }
    }
    return 0;
};

void Monster::displayStats()
{
    cout << "Statistics\n--------------\n";
    cout << "NAME\t" << name << endl;
    cout << "LEVEL\t" << level << endl;
    cout << "HEALTH\t" << health << "/" << health_max << endl;
    cout << "MANA\t" << mana << endl;
    cout << "PAttk\t" << PowAttack << endl;
    cout << "PDef\t" << PowDef << endl;
    cout << "MAttk\t" << MagAttack << endl;
    cout << "MDef\t" << MagDef << endl;
    cout << "EXP\t" << exper << endl;
    cout << "GOLD\t" << gold_nuggets << endl;
    cout << "--------------------\n";
}
